package com.my.fp.list;

import java.util.Collection;
import java.util.List;

/**
 * flatMap()的使用
 * <p>
 * <a href="https://www.jianshu.com/p/8d80dcb4e7e0">参考</a>
 *
 * @author: marshal
 * @date: 2021-12-08 5:07 PM
 */
public class FlatMapList {
    public static void main(String[] args) {
        var listA = List.of("a", "b", "c");
        var listB = List.of("x", "y", "z");
        var listC = List.of(listA, listB);

        // flatMap() 我的理解就是给多维List降维
        var listD = listC.stream().flatMap(Collection::stream).toList();
        System.out.println(listC); // [[a, b, c], [x, y, z]]
        System.out.println(listD); // [a, b, c, x, y, z]
    }
}
